package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.SysDianciFinishedRetrospectService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.SysDianciFinishedRetrospectForm;
import com.youlai.boot.system.model.query.SysDianciFinishedRetrospectQuery;
import com.youlai.boot.system.model.vo.SysDianciFinishedRetrospectVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 成品追溯前端控制层
 *
 * @author liwenbing
 * @since 2025-04-09 23:40
 */
@Tag(name = "成品追溯接口")
@RestController
@RequestMapping("/api/v1/sysDianciFinishedRetrospects")
@RequiredArgsConstructor
public class SysDianciFinishedRetrospectController  {

    private final SysDianciFinishedRetrospectService sysDianciFinishedRetrospectService;

    @Operation(summary = "成品追溯分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:sysDianciFinishedRetrospect:query')")
    public PageResult<SysDianciFinishedRetrospectVO> getSysDianciFinishedRetrospectPage(SysDianciFinishedRetrospectQuery queryParams ) {
        IPage<SysDianciFinishedRetrospectVO> result = sysDianciFinishedRetrospectService.getSysDianciFinishedRetrospectPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增成品追溯")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:sysDianciFinishedRetrospect:add')")
    public Result<Void> saveSysDianciFinishedRetrospect(@RequestBody @Valid SysDianciFinishedRetrospectForm formData ) {
        boolean result = sysDianciFinishedRetrospectService.saveSysDianciFinishedRetrospect(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取成品追溯表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:sysDianciFinishedRetrospect:edit')")
    public Result<SysDianciFinishedRetrospectForm> getSysDianciFinishedRetrospectForm(
        @Parameter(description = "成品追溯ID") @PathVariable Long id
    ) {
        SysDianciFinishedRetrospectForm formData = sysDianciFinishedRetrospectService.getSysDianciFinishedRetrospectFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改成品追溯")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:sysDianciFinishedRetrospect:edit')")
    public Result<Void> updateSysDianciFinishedRetrospect(
            @Parameter(description = "成品追溯ID") @PathVariable Long id,
            @RequestBody @Validated SysDianciFinishedRetrospectForm formData
    ) {
        boolean result = sysDianciFinishedRetrospectService.updateSysDianciFinishedRetrospect(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除成品追溯")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:sysDianciFinishedRetrospect:delete')")
    public Result<Void> deleteSysDianciFinishedRetrospects(
        @Parameter(description = "成品追溯ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = sysDianciFinishedRetrospectService.deleteSysDianciFinishedRetrospects(ids);
        return Result.judge(result);
    }
}
